package com.ruoyi.project.tool.swagger.WorkerController;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.framework.aspectj.lang.annotation.SignatureValidation;
import com.ruoyi.framework.interceptor.annotation.RepeatSubmit;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.project.system.domain.SysMobileUser;
import com.ruoyi.project.system.domain.SysOpinion;
import com.ruoyi.project.system.domain.SysUser;
import com.ruoyi.project.system.service.ISysOpinionService;
import com.ruoyi.project.system.service.ISysUserService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/mobileWorker/opinion/")
public class WorkOpinionController {

    @Autowired
    private ISysOpinionService sysOpinionService;

    @Autowired
    private ISysUserService sysUserService;
    /**
     *  工人端上传意见反馈
     */
    @SignatureValidation
    @PostMapping("addOpinion")
    private AjaxResult addOpinion(@RequestBody SysOpinion sysOpinion){
        sysOpinion.setInformationType("2");
        String username = SecurityUtils.getLoginUser().getUserName();
        SysUser sysUser = sysUserService.selectUserByUserName(username);
        sysOpinion.setUserId(sysUser.getUserId());
        return AjaxResult.success(sysOpinionService.insertSysOpinion(sysOpinion));
    }
    /**
     *  工人端查看意见反馈
     * */
    @SignatureValidation
    @ApiOperation("查询个人意见反馈")
    @GetMapping("queryOpinion")
    public AjaxResult queryOpinion()
    {
        String username = SecurityUtils.getLoginUser().getUserName();
        SysUser sysUser = sysUserService.selectUserByUserName(username);
        Long userId = sysUser.getUserId();
        return AjaxResult.success(sysOpinionService.queryUseropinion(userId));
    }
    /**
     * 用户端删除意见反馈
     * */
    @SignatureValidation
    @ApiOperation("删除个人意见反馈")
    @DeleteMapping("deleteOpinion")
    @RepeatSubmit
    public AjaxResult deleteOpinion(SysOpinion sysOpinion)
    {
        sysOpinionService.deleteSysOpinionById(sysOpinion.getOpinionId());
        return AjaxResult.success("删除成功");
    }
}
